﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
using System.Web;
using AnyOffice.Components;
using log4net;
namespace AnyOffice.general.qikan
{
    public partial class thumb : ModulePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Response.Buffer = true;
                Response.Clear();
                QikanInfo qikanInfo = QikanFactory.GetQikanInfo();
                if (qikanInfo != null)
                {
                    string str = (Request.QueryString["filename"] != null) ? Request.QueryString["filename"].ToString() : "";
                    Image image = Image.FromFile(qikanInfo.DiskPath + str.Replace("../", "").Replace("/", @"\"));
                    int width = image.Width;
                    int height = image.Height;
                    int num3 = 120;
                    if (Request.QueryString["upDownMaximum"] != null)
                    {
                        num3 = Convert.ToInt32(Request.QueryString["upDownMaximum"].ToString());
                    }
                    if ((image.Width > num3) || (image.Height > num3))
                    {
                        if (image.Width > image.Height)
                        {
                            width = num3;
                            height = (image.Height * num3) / image.Width;
                        }
                        else
                        {
                            width = (image.Width * num3) / image.Height;
                            height = num3;
                        }
                    }
                    Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(thumb.ThumbnailCallback);
                    Image image2 = image.GetThumbnailImage(width, height, callback, IntPtr.Zero);
                    image2.Save(Response.OutputStream, ImageFormat.Jpeg);
                    image2.Dispose();
                    image.Dispose();
                }
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("", exception);
                }
            }
        }
        public static bool ThumbnailCallback()
        {
            return false;
        }
    }
}
